package org.example.controller;


import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import org.example.service.Assistant;
import org.example.service.SeparateChatAssistant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LC4jController {

    @Autowired
    private OpenAiChatModel openAiChatModel;

    @Autowired
    private QwenChatModel qwenChatModel;


    @Autowired
    private Assistant assistant;

    @Autowired
    private SeparateChatAssistant separateChatAssistant;

//
//    /**
//     * openAi大模型DeepSeek
//     * @return
//     */
//    @GetMapping("/chat")
//    public String chatAi() {
//        String answer = openAiChatModel.chat("你好");
//        System.out.println(answer);
//        return answer;
//    }




//    /**
//     * 通义千问大模型
//     */
//    @GetMapping("/testQwen")
//    public String testQwen() {
//        //向模型提问
//        String answer = qwenChatModel.chat("你好");
//        //输出结果
//        System.out.println(answer);
//        return answer;
//    }


    /**
     * 使用AiServer进行智能体开发
     * @return
     */
    @GetMapping("/textAssistant")
    public String textAssistant(){
        String answer = assistant.chat("您好");
        System.out.println(answer);
        return answer;
    }



//    /**
//     * 使用AiServer进行聊天记忆开发
//     * @return
//     */
//    @GetMapping("/AiServices")
//    public String AiServices() {
//        //创建chatMemory
//        MessageWindowChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);
//        //创建AIService
//        Assistant assistant = AiServices
//                .builder(Assistant.class)
//                .chatLanguageModel(qwenChatModel)
//                .chatMemory(chatMemory)
//                .build();
//        //调用service的接口
//        String answer1 = assistant.chat("我是环环");
//        System.out.println(answer1);
//        String answer2 = assistant.chat("我是谁");
//        System.out.println(answer2);
//        return "answer";
//    }


    /**
     * 聊天记忆实现的智能体
     * @return
     */
    @GetMapping("/AiServices2")
    public String AiServices2() {
        String answer1 = assistant.chat("我是环环");
        System.out.println(answer1);
        String answer2 = assistant.chat("我是谁");
        System.out.println(answer2);
        return "使用接口实现聊天记忆！";
    }


    /**
     * 聊天记忆隔离的智能体
     * @return
     */
    @GetMapping("/AiServices33")
    public String AiServices33() {
        String answer1 = separateChatAssistant.chat(1, "我是环环");
        System.out.println(answer1);
        String answer2 = separateChatAssistant.chat(1, "我是谁");
        System.out.println(answer2);
        String answer3 = separateChatAssistant.chat(2, "我是谁");
        System.out.println(answer3);
        return "聊天记忆隔离的智能体！";
    }



    @GetMapping("/AiServices3")
    public String AiServices3(int memoryId, String userMessage) {
        String answer1 = separateChatAssistant.chat1(memoryId, userMessage, "xiaoming", 18);
        System.out.println(answer1);
        return answer1;
    }


}
